| Conditions | 3 |
| Paths | 2 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import path from 'path' |
||
| 15 | function publishNext(files, tt, cb, i = 0) { |
||
| 16 | var pub = files.shift() |
||
| 17 | if(typeof pub !== 'undefined' && pub !== null) { |
||
| 18 | |||
| 19 | var jsonObject = fse.readJsonSync(pub[processConfig.ABE_STATUS].path) |
||
| 20 | i++ |
||
| 21 | var p = new Promise((resolve) => { |
||
| 22 | if(typeof templatesTexts[jsonObject.abe_meta.template] === 'undefined' || templatesTexts[jsonObject.abe_meta.template] === null) { |
||
| 23 | templatesTexts[jsonObject.abe_meta.template] = cmsTemplates.template.getTemplate(jsonObject.abe_meta.template) |
||
| 24 | } |
||
| 25 | |||
| 26 | cmsData.source.getDataList(path.dirname(jsonObject.abe_meta.link), templatesTexts[jsonObject.abe_meta.template], jsonObject, true) |
||
| 27 | .then(() => { |
||
| 28 | jsonObject = abeExtend.hooks.instance.trigger('afterGetDataListOnSave', jsonObject) |
||
| 29 | |||
| 30 | var obj = { |
||
| 31 | type: jsonObject.abe_meta.status, |
||
| 32 | json: { |
||
| 33 | content: jsonObject |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | var page = new Page(obj.json.content.abe_meta.template, templatesTexts[jsonObject.abe_meta.template], obj.json.content, true) |
||
| 38 | |||
| 39 | cmsOperations.save.saveHtml( |
||
| 40 | path.join(config.root, processConfig.ABE_DESTINATION, jsonObject.abe_meta.link), |
||
| 41 | page.html |
||
| 42 | ) |
||
| 43 | |||
| 44 | obj = abeExtend.hooks.instance.trigger('afterSave', obj) |
||
|
|
|||
| 45 | |||
| 46 | trace('('+ getTime() + ') ' + i + ' - ' + pub[processConfig.ABE_STATUS].path.replace(config.root, '').replace(config.data.url, '') + ' (tpl: ' + jsonObject.abe_meta.template + ')') |
||
| 47 | resolve() |
||
| 48 | }, |
||
| 49 | () => { |
||
| 50 | error('generate-posts ERROR on ' + pub[processConfig.ABE_STATUS].path.replace(config.root, '').replace(config.data.url, '')) |
||
| 51 | resolve() |
||
| 52 | }) |
||
| 53 | }) |
||
| 54 | |||
| 55 | p.then(function () { |
||
| 56 | publishNext(files, tt, cb, i++) |
||
| 57 | }) |
||
| 58 | .catch(function (e) { |
||
| 59 | publishNext(files, tt, cb, i++) |
||
| 60 | error('error', e) |
||
| 61 | }) |
||
| 62 | }else { |
||
| 63 | cb(i) |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 93 | }) |